<template>
  <el-form :label-position="labelPosition" label-width="80px" :model="formInline" :rules="rules" ref="ruleForm">
    <el-form-item label="商品名称" prop="gname" >
      <el-input v-model="formInline.gname"></el-input>
    </el-form-item>
    <el-form-item label="商品品牌" prop="gbrand" >
      <el-input v-model="formInline.gbrand"></el-input>
    </el-form-item>
    <el-form-item label="商品类型" prop="gtype">
      <el-input v-model="formInline.gtype"></el-input>
    </el-form-item>
    <el-form-item label="店铺id" prop="did">
      <el-input v-model="formInline.did"></el-input>
    </el-form-item>
    <el-form-item label="商品描述">
      <el-input v-model="formInline.gdesc"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit('ruleForm')">提交</el-button>
      <el-button @click="black">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: "GoodsAdd",
  data() {
    return {
      labelPosition: 'right',
      formInline: {
        gname: '',
        gtype: '',
        gbrand:'',
        did:'',
        gdesc:'',

      },
      rules:{
        gname :[{required: true, message: '请输入', trigger: 'blur'}],
        gbrand :[{required: true, message: '请输入', trigger: 'blur'}],
        gtype :[{required: true, message: '请输入', trigger: 'blur'}],
        did :[{required: true, message: '请输入', trigger: 'blur'}]
      }
    };
  },
  methods:{
    onSubmit(formName){

      this.$refs[formName].validate((valid) => {
        if (valid) {
          var vm = this
          this.axios({
            method:"POST",
            url:"/api/goods/insert",
            data:{
              gname:vm.formInline.gname,
              gtype:vm.formInline.gtype,
              gbrand:vm.formInline.gbrand,
              did:vm.formInline.did,
              gdesc:vm.formInline.gdesc
            }
          }).then(function (res){
            if(res.data.code == 200){
              vm.$message(res.data.msg)
            }else{
              vm.$message(res.data.msg)
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    /*  var vm = this
      this.axios({
        method:"POST",
        url:"/api/goods/insert",
        data:{
          gname:vm.formInline.gname,
          gtype:vm.formInline.gtype,
          gbrand:vm.formInline.gbrand,
          did:vm.formInline.did,
          gdesc:vm.formInline.gdesc
        }
      }).then(function (res){
        if(res.data.code == 200){
          vm.$message(res.data.msg)
        }else{
          vm.$message(res.data.msg)
        }
      })*/
    },
    black(){
      this.$router.push('/Goods/List')
    }
  }
}
</script>

<style scoped>

</style>
